dashboardController.$inject = ['$location', '$http', '$interval'];
var $ = require('jquery')

function dashboardController($location, $http, $interval) {
    var vm = this;
    $interval(function() {
        $http({
            url: "/api/admin/manage/merchants/count",
            method: 'GET',
        }).then(function(response) {
            vm.merchant_count = response.data;
            vm.percent = {
                audit: (vm.merchant_count.audit / vm.merchant_count.all) * 100,
                white: (vm.merchant_count.white / vm.merchant_count.all) * 100,
                black: (vm.merchant_count.black / vm.merchant_count.all) * 100,
                reject: (vm.merchant_count.reject / vm.merchant_count.all) * 100,
            }

            $('#audit_merchant_percent').css('width', vm.percent.audit + '%');
            $('#white_merchant_percent').css('width', vm.percent.white + '%');
            $('#black_merchant_percent').css('width', vm.percent.black + '%');
            $('#reject_merchant_percent').css('width', vm.percent.reject + '%');

            $('#audit_merchant_bar_chart').css('y', 243 - 185 * (vm.merchant_count.audit / 20)).css('height', 185 * (vm.merchant_count.audit / 20));
            $('#white_merchant_bar_chart').css('y', 243 - 185 * (vm.merchant_count.white / 20)).css('height', 185 * (vm.merchant_count.white / 20));
            $('#black_merchant_bar_chart').css('y', 243 - 185 * (vm.merchant_count.black / 20)).css('height', 185 * (vm.merchant_count.black / 20));
            $('#reject_merchant_bar_chart').css('y', 243 - 185 * (vm.merchant_count.reject / 20)).css('height', 185 * (vm.merchant_count.reject / 20));

            var audit_first_Point = '206,51';
            var audit_second_Point = {
                x: 206 + 80 * Math.sin(2 * Math.PI * (vm.percent.audit / 100)),
                y: 131 - 80 * Math.cos(2 * Math.PI * (vm.percent.audit / 100))
            };
            var white_first_Point = {
                x: 206 + 80 * Math.sin(2 * Math.PI * (vm.percent.audit + vm.percent.reject + vm.percent.black) / 100),
                y: 131 - 80 * Math.cos(2 * Math.PI * (vm.percent.audit + vm.percent.reject + vm.percent.black) / 100)
            };
            var white_second_Point = '206,51';
            var black_first_Point = {
                x: 206 + 80 * Math.sin(2 * Math.PI * ((vm.percent.audit + vm.percent.reject) / 100)),
                y: 131 - 80 * Math.cos(2 * Math.PI * ((vm.percent.audit + vm.percent.reject) / 100))
            };
            var black_second_Point = {
                x: 206 + 80 * Math.sin(2 * Math.PI * ((vm.percent.audit + vm.percent.reject + vm.percent.black) / 100)),
                y: 131 - 80 * Math.cos(2 * Math.PI * ((vm.percent.audit + vm.percent.reject + vm.percent.black) / 100))
            };
            var reject_first_Point = {
                x: 206 + 80 * Math.sin(2 * Math.PI * ((vm.percent.audit) / 100)),
                y: 131 - 80 * Math.cos(2 * Math.PI * ((vm.percent.audit) / 100))
            };
            var reject_second_Point = {
                x: 206 + 80 * Math.sin(2 * Math.PI * ((vm.percent.audit + vm.percent.reject) / 100)),
                y: 131 - 80 * Math.cos(2 * Math.PI * ((vm.percent.audit + vm.percent.reject) / 100))
            };

            var audit_lenghty = (vm.percent.audit / 100) > 0.5 ? 1 : 0;
            var white_lenghty = (vm.percent.white / 100) > 0.5 ? 1 : 0;
            var black_lenghty = (vm.percent.black / 100) > 0.5 ? 1 : 0;
            var reject_lenghty = (vm.percent.reject / 100) > 0.5 ? 1 : 0;

            $('#audit_circle_chart').attr('d', 'M206,131L' + audit_first_Point + 'A80,80,0,' + audit_lenghty + ',1,' + audit_second_Point.x + ',' + audit_second_Point.y + 'L206,131        A0,0,0,0,0,206,131');
            $('#white_circle_chart').attr('d', 'M206,131L' + white_first_Point.x + ',' + white_first_Point.y + 'A80,80,0,' + white_lenghty + ',1,' + white_second_Point + 'L206,131        A0,0,0,0,0,206,131');
            $('#black_circle_chart').attr('d', 'M206,131L' + black_first_Point.x + ',' + black_first_Point.y + 'A80,80,0,' + black_lenghty + ',1,' + black_second_Point.x + ',' + black_second_Point.y + 'L206,131        A0,0,0,0,0,206,131');
            $('#reject_circle_chart').attr('d', 'M206,131L' + reject_first_Point.x + ',' + reject_first_Point.y + 'A80,80,0,' + reject_lenghty + ',1,' + reject_second_Point.x + ',' + reject_second_Point.y + 'L206,131        A0,0,0,0,0,206,131')
        })
    }, 2000);


}

module.exports = dashboardController;